<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>『 知音培训信息管理平台』</title>
	<script type="text/javascript" src="__PUBLIC__/Resourse/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Resourse/js/jquery.cookie.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Resourse/themes/default/easyui.css" id="easyuiTheme">
	<script type="text/javascript" charset="UTF-8" src="__PUBLIC__/Resourse/js/changeEasyuiTheme.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Resourse/themes/icon.css">
	<script type="text/javascript" src="__PUBLIC__/Resourse/js/jquery.easyui.min.js"></script>
	<style type="text/css">
		body {
			margin:0px;
			padding:0px;
			width:100%;
			height:100%;
		}
		.formStyle{  
            margin:0;  
            padding:10px 10px 30px 5px;  
       }  
       .ftitle{  
            font-size:14px;  
            font-weight:bold;  
            padding:5px 0;  
            margin-bottom:10px;  
            border-bottom:1px solid #ccc;  
        }  
       .fitem{  
            margin-bottom:5px;  
       }  
        .fitem label{  
           display:inline-block;  
            width:80px;  
        }
        .formText {
        	width : 200px;
        }  
	</style>
	<script type="text/javascript">
		var flUrl ="";
		var itemUrl="";
		
		$(function() {		
			 $("#tt").tree({   
			     url:"__URL__/getDictionaryTree", //这里接受的是JSON数据，通过Thinkphp 的Action得到
			     lines:true,
			     onClick: function(node){
						var queryParams = $('#dg').datagrid('options').queryParams;  
				        queryParams.PARENT_ID = node.id;  
				        //重新加载datagrid的数据  
				        $("#dg").datagrid('reload');  
				}
			  });
			$(window).resize(function(){
				$('#dg').datagrid('resize');
			});
			
			//设置分页控件   
		    var p = $('#dg').datagrid('getPager');  
		    $(p).pagination({  
		        pageSize: 10,//每页显示的记录条数，默认为10   
		        pageList: [5,10,15],//可以设置每页记录条数的列表   
		        beforePageText: '第',//页数文本框前显示的汉字   
		        afterPageText: '页    共 {pages} 页',  
		        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',  
		        /*onBeforeRefresh:function(){ 
		            $(this).pagination('loading'); 
		            alert('before refresh'); 
		            $(this).pagination('loaded'); 
		        }*/  
		    });  
﻿
		});
		
		$(document).ready(function(){	
			var skin = $.cookie('easyuiThemeName');
			if (skin != null && typeof skin != undefined) {
				changeThemeFun(skin);
			}
			//expandAll();		
		});
		
		function newFL(){  
			$('#dlg').dialog('open').dialog('setTitle','新建字典分类');  
			$('#fm').form('clear');  
			flUrl =  '__URL__/add';
		 }
		
        function reloadFlTree(){
            var node = $('#tt').tree('getSelected');
            if (node) {
                $('#tt').tree('reload', node.target);
            }
            else {
                $('#tt').tree('reload');
            }
        }
		
		 function saveFL(){  
		 	//var val = $('#cc').combotree('getValue');

           	$('#fm').form('submit',{  
                url: flUrl,  
                onSubmit: function(){  
                   return $(this).form('validate');  
                },  
                success: function(data){  
                    var result = eval('('+data+')');  
                    debugger;
                    if (result.errorMsg){  
                       $.messager.show({  
                           title: '消息',  
                           msg: result.errorMsg  
                        });  
                    } else {  
                    	$.messager.alert('消息','操作成功!','info');
                        $('#dlg').dialog('close');      	// close the dialog  
                        //$('#tt').tree('reload');
                        reloadFlTree();
                    }  
                }  
            });  
	     } 
		 
       function editFL(){  
           var node = $('#tt').tree('getSelected');
           if (node){  
	 	       $('#cc').combotree('setValue', node.attributes.parent_id);
               $('#dlg').dialog('open').dialog('setTitle','编辑分类');  
               $('#fm').form('load',{
            	   		Id:node.id,
            	   		FL_MC:node.text,
            	   		FL_VALUE:node.attributes.FL_VALUE
               		});  
               }else{
            	   $.messager.alert('消息','请选择一个分类!','info');
               }
            flUrl =  '__URL__/save/id/'+node.id;
        }  
	 
	    function destroyFL(){
	           var node = $('#tt').tree('getSelected');
	           if (node){  
	                $.messager.confirm('Confirm','Are you sure you want to destroy this Dictionary and Dictionary Item?',function(r){  
	                   if (r){  
	                      $.post('__URL__/del',{id:node.id},function(result){  
	                            if (result.success){  
	                            	reloadFlTree();    // reload the  data  
	                            } else {  
	                               $.messager.show({   // show error message  
	                                    title: 'Error',  
	                                    msg: result.errorMsg  
	                                });  
	                           }  
	                       },'json');  
	                    }  
	                });  
	            }else{
	            	   $.messager.alert('消息','请选择一个分类!','info');
	            }  
	       }  
	    
	      function newItem(){  
	           $('#dlgItem').dialog('open').dialog('setTitle','新建字典数据项');  
	           $('#fmItem').form('clear');  
	           itemUrl = '__URL__/addItem'; 
	       }  
	        
	       function editItem(){  
	           var row = $('#dg').datagrid('getSelected');  
	            if (row){  
	               $('#dlgItem').dialog('open').dialog('setTitle','编辑字典数据项');  
	               $('#fmItem').form('load',row);  
	               itemUrl =  '__URL__/saveItem/id/'+row.Id;  
	           }else{
	        	   $.messager.alert('消息','请选择一个数据项!','info');
	           }  
	       }
	       
	      function reloadDataGrid(){
	    	  var flId= $('#ccItem').combotree('getValue');
	          if (flId) {
					var queryParams = $('#dg').datagrid('options').queryParams;  
			        queryParams.PARENT_ID = flId;  
			        //重新加载datagrid的数据  
			        $("#dg").datagrid('reload');  
	          }else {
	        	  $("#dg").datagrid('reload');   
	          }
	      }
	       
	      function saveItem(){  
	           $('#fmItem').form('submit',{  
	               url: itemUrl,  
	                onSubmit: function(){  
	                   return $(this).form('validate');  
	                },  
	                success: function(result){  
	                    var result = eval('('+result+')');  
	                    if (result.errorMsg){  
	                       $.messager.show({  
	                            title: 'Error',  
	                           msg: result.errorMsg  
	                        });  
	                    } else {  
	                    	$.messager.alert('消息','操作成功!','info');
	                        $('#dlgItem').dialog('close');      // close the dialog  		
	                        reloadDataGrid();
	                        //$('#dg').datagrid('reload');    // reload the user data  
	                    }  
	                }  
	            });  
	      }
	      
	     function destroyItem(){  
	           var row = $('#dg').datagrid('getSelected');  
	            if (row){  
	                $.messager.confirm('Confirm','Are you sure you want to destroy this Dictionary Item?',function(r){  
	                   if (r){  
	                      $.post('__URL__/delItem',{id:row.Id},function(result){  
	                            if (result.success){  
	                            	reloadDataGrid();
	                              	//$('#dg').datagrid('reload');    // reload the user data  
	                            } else {  
	                               $.messager.show({   // show error message  
	                                    title: 'Error',  
	                                    msg: result.errorMsg  
	                                });  
	                           }  
	                       },'json');  
	                    }  
	                });  
	            }  
	       }  

	</script>
</head>
<body class="easyui-layout" style="border-width:50px;margin:0;">
	<div region="west" split="true" title="字典分类" style="width:150px;padding:10px;" class="cs-west">
			<ul id="tt"></ul>  
	</div>
	<div id="mainPanle"  region="center"  border="false" title="列表" >
		<table id="dg" class="easyui-datagrid" style="margin:0",
							data-options="rownumbers:true,
												singleSelect:true,
												height:'auto',
												fit:true,
												loadMsg:'数据加载中请稍后……',  
												autoRowHeight:false,
												pagination:true,
												pageSize:10,
												url:'__URL__/read/',
												toolbar:'#tb' 
								">
			<thead>
				<tr>
					<th data-options="field:'Id',fitColumns: true,hidden:true">Id</th>
					<th data-options="field:'ITEM_FLID',fitColumns: true,align:'center'">所属分类</th>
					<th data-options="field:'ITEM_KEY',fitColumns: true,align:'center'">数据项名称</th>
					<th data-options="field:'ITEM_VALUE',itColumns: true,align:'center'">数据项值</th>
					<th data-options="field:'ITEM_PARAM1',itColumns: true,align:'center'">扩展参数1</th>
					<th data-options="field:'ITEM_PARAM2',itColumns: true,align:'center'">扩展参数2</th>
					<th data-options="field:'ITEM_BZ',itColumns: true,align:'center'">备注</th>
				</tr>
		</thead>
		</table>
		<div id="tb" style="padding:5px;height:auto">
			<div style="margin-bottom:5px">
			 	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newFL()">添加分类</a>  
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editFL()">编辑分类</a>  
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyFL()">删除分类</a>  
			
				<a href="javascript:void(0)"" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">添加数据项</a>  
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">编辑数据项</a>  
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyItem()">删除数据项</a>  
			</div>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"  closed="true" buttons="#dlg-buttons">  
        <div class="ftitle">字典分类信息</div>  
        <form id="fm" class="formStyle"  method="post" novalidate>
            <div class="fitem">  
                <label>所属分类:</label> 
               	<input id="cc"  name="PARENT_ID"  class="easyui-combotree" data-options="url:'__URL__/getDictionaryChooseTree',required:true" style="width:200px;">
            </div>    
            <div class="fitem">  
                <label>分类名称:</label>  
               	<input name="FL_MC" class="easyui-validatebox" required="true">  
            </div>  
            <div class="fitem">  
                <label>分类标识:</label>  
                <input name="FL_VALUE" class="easyui-validatebox" required="true">  
            </div>  
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveFL()">保存</a>  
       <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
    </div>
    <div id="dlgItem" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"  closed="true" buttons="#dlgItem-buttons">  
        <div class="ftitle">数据项信息</div>  
        <form id="fmItem" class="formStyle"  method="post" novalidate>
            <div class="fitem">  
                <label>所属分类:</label> 
                <input name="id"  type="hidden">
               	<input id="ccItem"  name="ITEM_FLID"  class="easyui-combotree" data-options="url:'__URL__/getDictionaryChooseTree',required:true" style="width:200px;">
            </div>    
            <div class="fitem">  
                <label>数据项名称:</label>  
               	<input name="ITEM_KEY" class="easyui-validatebox" required="true">  
            </div>  
            <div class="fitem">  
                <label>数据项值:</label>  
                <input name="ITEM_VALUE" class="easyui-validatebox" >  
            </div>
            <div class="fitem">  
                <label>扩展项值1:</label>  
                <input name="ITEM_PARAM1" class="easyui-validatebox" >  
            </div>  
            <div class="fitem">  
                <label>扩展项值2:</label>  
                <input name="ITEM_PARAM2" class="easyui-validatebox" >  
            </div>
            <div class="fitem">  
                <label>备注:</label>  
                <textarea name="ITEM_BZ" style="height:60px;"></textarea>
            </div>     
        </form>  
    </div>  
    <div id="dlgItem-buttons">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveItem()">保存</a>  
       <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgItem').dialog('close')">取消</a>  
    </div> 
</body>
</html>